﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SuperShell.Common.LinqExtensions
{
	public static class EnumerableExtension
	{
		/// <summary>
		/// Splits source into two streams
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="source">Source items</param>
		/// <param name="predicate"></param>
		/// <returns>
		/// List of two streams.
		/// Items in first stream return true when applied to predicate.
		/// Items in second stream return false.
		/// </returns>
		public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> source,
										Func<T, bool> predicate)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			yield return source.Where(predicate);
			yield return source.Where(t => !predicate(t));
		}
	}
}
